#!/usr/bin/env node
const readline = require('readline');
const process = require('process');
function createPrompt (question, resolve, reg) {
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    rl.question(question, (answer) => {
        // 对答案进行处理
        rl.close();
        if (reg) {
            if (reg.test(answer)) {
                resolve(answer);
            } else {
                createPrompt (question, resolve, reg);
            }
        } else {
            resolve(answer);
        }
    });
}
module.exports = function prompt (question, reg) {
    return new Promise ((resolve, reject) => {
        createPrompt(question, resolve, reg);
    })
};
